%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55
% Main File
% Date: August 2014
% Author: Nitya
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%55

clear all
clc
cd 'dir'

diary on
global sample_est nu_i mu
sample = csvread('sample_static_all_nsU_update.txt');
sample_est=sample;
size(sample)


om0  = 0.3;
psi0 = 0.3;

startval = [om0 psi0]; 


[theta, fval, exitflag]= fminsearch('est_obj_scale_weight',startval);

disp('Exitflag')
disp(exitflag)

disp('Actual Point Estimates')
disp(theta)

disp('Mean nu_i')
disp(mean(nu_i))

disp('Std Deviation nu_i')
disp(std(nu_i))

disp('Mean mu')
disp(mean(mu))

disp('Std mu')
disp(std(mu))

%disp('Mean mu')
%disp(mean(mu))

%Bootstrap


N_sample = size(sample,1)


rand('seed',1234);


N = xx;
theta_bs = zeros(N,2);
nu_info_bs= zeros(N,2);
draws = zeros(N_sample,1);
fval=0;
exitflag=0;
%mu0 = 0.5;
om0 = 0.3;
psi0 = 0.3;
tries=1; %number of bootstraps done

startval = [om0 psi0];

while tries <=N
	%sample_bs = zeros(size(sample));
	draws=ceil(N_sample*rand(N_sample,1));
	sample_est=sample(draws,:);

[temp, fval, exitflag] = fminsearch('est_obj_scale_weight',startval);

	if exitflag==1 & 0 <= temp(1) & 0 <= temp(2) & temp(1) <= 2 & temp(2) <= 2
		theta_bs(tries,:)=temp;
		tries=tries+1;
		nu_info_bs(tries,:)=[mean(nu_i) std(nu_i)];
	end


end

theta_bs

disp('Bootstrap Std Dev')
disp(std(theta_bs))

disp('Std Deviation of Bootstrap Means and Std Dev of BS std deviations')
disp(std(nu_info_bs))

	